package com.wmada.toolkit.common.secure;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

/**
 * @author will.ma
 * @date 2018-5-14
 */
public class FastKey extends ThreadLocal<Random> {

    private static final Logger LOGGER = LoggerFactory.getLogger(FastKey.class);

    private static final FastKey Generator = new FastKey();

    public static byte[] getKey(int keyLength) {
        byte[] code = new byte[keyLength];
        Generator.get().nextBytes(code);
        return code;
    }

    private FastKey() { }

    @Override
    protected Random initialValue() {
        Random random = new Random();
        random.setSeed(System.nanoTime());
        return random;
    }
}
